package com.company.project.common.utils;

import com.alibaba.fastjson.JSON;
import com.baidu.techain.sdk.model.Message;
import com.baidu.techain.sdk.model.MessageResult;
import com.baidu.techain.sdk.model.Notification;
import com.baidu.techain.sdk.model.PushResult;
import com.baidu.techain.sdk.push.IPushClient;
import com.baidu.techain.sdk.push.PushClient;
import com.company.project.common.aop.LogAspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class BaiduPush {

    private static final Logger logger = LoggerFactory.getLogger(BaiduPush.class);

    public static PushResult<MessageResult> PushMessageByPushIds(String title, String content, List<String> pushIdList){
        String APPKEY = "700000060";
        String MASTERSECRET = "0b76def477c87b1a19f7a4efff40c6cd";
        IPushClient pushClient = new PushClient(APPKEY, MASTERSECRET);

        Message msg = new Message();
        //构建通知栏消息
        Notification notification = new Notification.Builder().
                title(title).
                content(content).
                build();

        msg.setMessageType(0); //设置消息类型为通知栏消息
        msg.setNotification(notification);
        //向设备id为"123"的设备发送消息
//        PushResult<MessageResult> result = pushClient.pushMessageByPushId(msg, "5|0|f0138ebdbf7b718bf65cd7aecdfcf5fe");
//        List<String> pushIdList = new ArrayList<String>();
//        pushIds.add("5|0|a7105cad3a863fdd91a2d7fee8b69072");
        PushResult<MessageResult> result = pushClient.pushMessageByPushIds(msg, pushIdList);

        logger.info("百度推送标题：" + title);
        for(String pushId: pushIdList){
            logger.info("百度推送pushId：" + pushId);
        }
        if (result != null) {
            logger.info("百度推送结果：" + JSON.toJSONString(result));
        }

        return result;
    }

    public static void main(String[] args) {
        List<String> pushIdList = new ArrayList<>();
        pushIdList.add("5|0|63a2f64e8af5178d65ec233c1cd51ddf");
        BaiduPush.PushMessageByPushIds("任建波", "content", pushIdList);
    }

}
